#include "link_list.h"

linklist create_empty_linklist ()
{
	linklist h = NULL;
	h = (linklist)malloc(sizeof(linknode));
	if(h == NULL)
	{
		printf("fail to malloc\n");
		return NULL;
	}
	h->next = NULL;
	return h;
}
int insert_linknode (linklist h,link_datatype x)
{
	linklist p = NULL;
	p = (linklist)malloc(sizeof(linknode));
	if(p == NULL)
	{
		printf("fail to malloc\n");
		return -1;
	}
	p->data = x;
	p->next = h->next;
	h->next = p;
	return 0;
}
link_datatype get_linknode(linklist h)
{
	linklist p = NULL;
	link_datatype data;
	if(empty_linklist(h))
	{
		printf("list_empty\n");
		return NULL;
	}
	p = h->next;
	data = p->data;
	h->next = p->next;
	free(p);
	p = NULL;
	return data;
}
int empty_linklist (linklist h)
{
	return h->next == NULL;
}
